package com.dylan.历史.java8.lambda表达式;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by Dylan on 2018/7/19.
 */
public class 静态方法 {

    public static void main(String[] args) {
        List<Person> people = Arrays.asList(new Person(1L, "ankang"), new Person(2L, "yaojiankang"), new Person(3L, "wanghan"));
        // 使用Comparator接口的静态方法comparing进行排序.该方法接收"提取键"函数,并产生一个用来比较所提取出的键的比较器
        Collections.sort(people, Comparator.comparing(Person::getName));
        System.out.println(people);
        // 使用Comparator接口的静态方法comparing进行排序.该方法接收"提取键"函数,并使用指定比较器实现一个用来比较所提取出的键的比较器
        Collections.sort(people, Comparator.comparing(Person::getName, (o1, o2) -> o2.compareTo(o1)));
        System.out.println(people);
    }

    public static class Person {
        private Long id;
        private String name;

        public Person(Long id, String name) {
            this.id = id;
            this.name = name;
        }

        public String getName() {
            return name;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    '}';
        }
    }
}
